<template>
    <div class="edit">
        <h3 style='text-align:center;font-weight:700;margin:10px'>在线诊疗医师服务费新增</h3>
        <div class="main">
            <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="90" label-position="left">
                <Row gutter="32" class="infobox">
                    <p class="title">项目基本信息</p>
                    <Col span="8">
                        <FormItem prop="projectCategory" label="项目类别：">
                            <Select clearable v-model="formValidate.projectCategory" style='width:100%;' @on-change='projectCategoryChange(formValidate.projectCategory)'>
                                <Option style='text-align:center;' :value="item.id" v-for='item in projectCategoryList' :key='item.id'>{{ item.name }}</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="项目名称：" prop="name">
                            <Input v-model="formValidate.name" placeholder="输入项目名称" :maxlength="50" style='width:100%;'></Input>
                        </FormItem>
                        <FormItem prop="chargingUnit" label="项目收费单位：" :label-width="110">
                            <Select v-model="formValidate.chargingUnit" style='width:100%;'>
                                <Option style='text-align:center;' :value="item.id" :key='item.id' v-for='item in chargingUnit'>{{ item.name }}</Option>
                            </Select>
                        </FormItem>
                        <FormItem label="项目物价码：" class="hongdian">
                            <Input v-model="formValidate.priceCode" :maxlength="120" placeholder="输入项目物价码" style='width:100%;'></Input>
                        </FormItem>
                    </Col>
                    <Col span="8">
                        <FormItem label="业务模块：" prop="modular" v-if="formValidate.projectCategory =='1' || formValidate.projectCategory =='2' ">
                            <!-- 咨询列表 -->
                            <Select v-model="formValidate.modular" style='width:100%;' v-show='formValidate.projectCategory == 1' @on-change='changeModular(formValidate.modular)'>
                                <Option  style='text-align:center;' :value="item.id" v-for='(item,index) in 
                                consultList' :key='index'>{{ item.name }}</Option>
                            </Select>
                            <!-- 问诊列表 -->
                            <Select v-model="formValidate.modular" style='width:100%;' v-show='formValidate.projectCategory == 2'>
                                <Option  style='text-align:center;' :value="item.id" v-for='(item,index) in inquiryList' :key='index'>{{ item.name }}</Option>
                            </Select>
                            <!-- 检查检验体检列表 -->
                            <Select v-model="formValidate.modular" style='width:100%;' v-show="formValidate.projectCategory !='1' && formValidate.projectCategory !='2' && formValidate.projectCategory !=''">
                                <Option  style='text-align:center;' :value="item.id" v-for='(item,index) in checklist' :key='index'>{{ item.name }}</Option>
                            </Select>
                            <!-- 未选择时的列表 -->
                            <Select v-model="formValidate.modular" style='width:100%;' v-if='!formValidate.projectCategory'>
                                <Option  style='text-align:center;' :value="index" v-for='(item,index) in modular' :key='index'>{{ item }}</Option>
                            </Select>
                        </FormItem>
                        <FormItem prop="title" label="关联职称：" v-if="formValidate.projectCategory =='1' || formValidate.projectCategory =='2' ">
                            <Select v-model="formValidate.title"  style='width:100%;'>
                                <Option
                                    v-for="item in titleList"
                                    :value="item.dictType"
                                    :key="item.dictType"
                                    style='text-align:center'
                                >{{item.dictName}}</Option>
                            </Select>
                        </FormItem>
                        <FormItem prop="classify" label="项目分类：" v-if="formValidate.projectCategory !='1' && formValidate.projectCategory !='2' && formValidate.projectCategory !=''" style='width:100%;'>
                            <Select v-model="formValidate.classify" 
                             @on-open-change='getClassificationList(0)' style='width:65%;'>
                                <Option
                                    v-for="item in classificationList"
                                    :value="item.id"
                                    :key="item.id"
                                    :label='item.typeName'
                                    style='text-align:center'
                                >{{item.typeName}}</Option>
                            </Select>
                            &nbsp;&nbsp;
                            <Button type='primary' @click="addClassification">
                                <i class = "iconfont icon-add" style="font-size:14px;margin-right:5px"></i>
                            </Button>
                        </FormItem>
                        <FormItem label="执行科室：" v-if="formValidate.projectCategory !='1' && formValidate.projectCategory !='2' && formValidate.projectCategory !=''" prop="executiveDeptId">
                            <Select v-model="formValidate.executiveDeptId"  style='width:100%;'>
                                <Option
                                    v-for="item in departmentList"
                                    :value="item.id"
                                    :key="item.dictType"
                                    style='text-align:center'
                                >{{item.deptNickname}}</Option>
                                <!-- dictName -->
                            </Select>
                        </FormItem>
                        <FormItem prop="priceBasis" label="项目平台收费标准（元）：" :label-width="170">
                            <InputNumber :max="9999" :min="0" v-model="formValidate.priceBasis" placeholder="0.00" style='width:100%;'></InputNumber>
                        </FormItem>
                    </Col>
                    <Col span="8">
                        <FormItem label="咨询/问诊形式：" prop="consultationForm" v-if="formValidate.projectCategory =='1' || formValidate.projectCategory =='2' " :label-width="110">
                            <Select v-model="formValidate.consultationForm" style='width:100%;' v-if="formValidate.projectCategory =='1' && formValidate.modular ==0">
                                <Option  style='text-align:center;' :value="item.id" v-for='(item,index) in 
                                consultFormList' :key='index'>{{ item.name }}</Option>
                            </Select>
                            <Select v-model="formValidate.consultationForm" style='width:100%;' v-else>
                                <Option  style='text-align:center;' :value="item.id" v-for='(item,index) in 
                                consultationFormList' :key='index'>{{ item.name }}</Option>
                            </Select>
                        </FormItem>
                        <FormItem prop="position" label="默认部位/标本类型：" v-if="formValidate.projectCategory !='1' && formValidate.projectCategory !='2' && formValidate.projectCategory !=''" :label-width="140" style='width:100%;'>
                            <Select v-model="formValidate.position"  style='width:62%;'  @on-open-change='getClassificationList(1)'>
                                <Option
                                    v-for="item in specimen"
                                    :value="item.id"
                                    :key="item.id"
                                    :label='item.typeName'
                                    style='text-align:center'
                                >{{item.typeName}}</Option>
                            </Select>
                            &nbsp;&nbsp;
                            <Button type='primary' @click="addposition">
                                <i class = "iconfont icon-add" style="font-size:14px;margin-right:5px"></i>
                            </Button>
                        </FormItem>
                        <FormItem label="项目规格：" class="hongdian">
                            <Input v-model="formValidate.norms" :maxlength="120" placeholder="输入项目规格" style='width:100%;'></Input>
                        </FormItem>
                        <FormItem label="项目收费依据：" :label-width="110" class="hongdian">
                            <Input v-model="formValidate.charge" :maxlength="50" placeholder="输入收费依据" style='width:100%;'></Input>
                        </FormItem>
                    </Col>
                    <Col span="15">   
                        <FormItem class="hongdian" label="启用标识：" v-if="formValidate.projectCategory =='1' || formValidate.projectCategory =='2' ">
                            <iSwitch size="large" v-model="formValidate.status" @on-change="changeStatus(formValidate.status)">
                                <span slot="open">开启</span>
                                <span slot="close">关闭</span>
                            </iSwitch>
                            <span style='margin-left:10px;color:#ff9966;'>每个职称对应每个业务模块有且只有一个收费项目启用，停用后可能会导致业务模块不能检索到医生。</span>
                            <!-- color:#ff9800 -->
                        </FormItem>                    
                        <Row>
                            <Col span="8">
                                <FormItem label="启用标识：" v-if="formValidate.projectCategory !='1' && formValidate.projectCategory !='2' " class="hongdian">
                                    <iSwitch size="large" v-model="formValidate.status" @on-change="changeStatus(formValidate.status)">
                                        <span slot="open">开启</span>
                                        <span slot="close">关闭</span>
                                    </iSwitch>
                                    <!-- color:#ff9800 -->
                                </FormItem>
                            </Col>
                            <Col span="7">
                                <FormItem label="是否为预约项：" v-if="formValidate.projectCategory !='1' && formValidate.projectCategory !='2' " :label-width="100">
                                    <iSwitch size="large" v-model="formValidate.isubscribe" @on-change="changeisubscribe(formValidate.isubscribe)" :disabled="isubscribeDisable">
                                        <span slot="open">开启</span>
                                        <span slot="close">关闭</span>
                                    </iSwitch>
                                </FormItem>
                            </Col>
                            <Col span="7">
                                <FormItem label="患者可否直接预约：" v-if="formValidate.projectCategory !='1' && formValidate.projectCategory !='2' " :label-width="120">
                                    <iSwitch size="large" v-model="formValidate.ipatientAppointment" :disabled="ipatientAppointmentDisable">
                                        <span slot="open">开启</span>
                                        <span slot="close">关闭</span>
                                    </iSwitch>
                                </FormItem>
                            </Col>
                        </Row>
                    </Col>
                    <Col span="24">
                        <FormItem label="备注说明：" class="hongdian">
                            <Input v-model="formValidate.reason" :maxlength="500" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入备注"></Input>
                        </FormItem>
                    </Col>
                </Row>       
                <Row gutter="32" class="infobox">
                    <p class="title">院内系统项目关联</p>
                    <Col span="22">
                        <FormItem label="对应HIS项目：" :label-width="95"  class="hongdian">
                            <Table @on-selection-change="selectChange" :loading="tableLoading" border stripe :columns="columns1" :data="data1" ref="table1" style="width: 100%">
                                <template slot="num" slot-scope="props" >
                                    <InputNumber v-model="props.row.num" placeholder="请输入关联数量" :min='1' :max="999" @on-change='money'></InputNumber> 
                                </template>
                            </Table>    
                            <p v-if="this.data1.length" style="border:1px solid #ccc;border-top:none;font-size: 14px; padding-left: 800px; ">总计： <span>{{zj}}元</span></p>       
                        </FormItem>
                     </Col> 
                     <Col span="2">
                        <Button type='primary' @click="his">
                            <i class = "iconfont icon-add" style="font-size:14px;margin-right:5px"></i>
                        </Button>
                     </Col>
                </Row>
            </Form>
            <div style='textAlign: center;'>
                <Button type='primary' @click='handleSubmit("formValidate")' :disabled="isDisable" style="width:95px;height:35px;">
                    <Icon type="ios-checkmark" style="margin-right: 5px" />确认新增
                </Button>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <Button @click='handleReset("formValidate")' style="width:75px;height:35px;">
                    <i class = "iconfont icon-butongyi" style="font-size:14px;margin-right:5px"></i>取消
                </Button>
            </div>
            <Modal
                v-model = "modalStatus1"
                width='1000'
                :styles="{height: '100px'}"
                :closable='false'
                :mask-closable="false"
                footer-hide>   
                <h3 style='text-align:center;font-weight:700;margin:10px'>{{whtitle}}</h3>  
                <div style="height:40px">
                    <Button type='info'  @click="add(data2)">
                        <i class = "iconfont icon-add" style="font-size:14px;margin-right:5px"></i>新增
                    </Button>   
                    <span style="color:#ff9966;margin-left:20px">( 提示：每次只可新增一条 )</span>        
                </div>
                <Table ref="myTable" @on-selection-change="selectChange" :loading="tableLoading" border stripe :columns="columns2" :data="data2" height="600">
                    <template slot="inspection" slot-scope="props">
                        <span >{{ props.row.inspection }}</span>
                    </template>
                    <template slot="typeName" slot-scope="props" >
                        <Input v-model="props.row.typeName" placeholder="请输入分类名称" v-if="editIndex == props.idx || bc == '1'" maxlength="50"></Input>
                        <span v-else>{{ props.row.typeName }}</span>
                    </template>
                     <template slot="sort" slot-scope="props" >
                        <InputNumber v-model="props.row.sort" placeholder="请输入排序" v-if="editIndex == props.idx || bc == '1'" :max='999999' :min='0'></InputNumber>
                        <span v-else>{{ props.row.sort }}</span>
                    </template>
                     <template slot="relatingCodes" slot-scope="props" >
                        <Input v-model="props.row.relatingCodes" placeholder="请输入关联码" v-if="editIndex == props.idx || bc == '1'" maxlength="6"></Input>
                        <span v-else>{{ props.row.relatingCodes }}</span>
                    </template>
                     <!-- 操作 -->
                    <template slot="idel" slot-scope="props" >
                        <div v-if="editIndex == props.idx">
                            <Button @click="editsub(data2,props.idx)" type='primary' size="small">
                                <i class = "iconfont icon-tongyi"></i>保存
                            </Button>
                            <Button @click="editIndex = -1" size="small">
                                <i class = "iconfont icon-butongyi" ></i> 取消
                            </Button>
                        </div>
                        <div v-if="editIndex != props.idx && bj =='1' ">
                            <Button  type='primary' size="small"  @click="handleEdit(row,props.idx)">
                                <i class = "iconfont icon-bianji" style="margin-right:5px"></i> 编辑
                            </Button>
                        </div>
                        <div v-if="bc =='1' ">
                            <Button  type='primary' size="small"  @click="sub(data2,props.idx)">
                                <Icon type="ios-checkmark" style="margin-right: 5px" />
                                保存
                            </Button>
                        </div>                   
                    </template>
                </Table> 
                <div style='textAlign: center;margin:10px'>                   
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <Button @click='back'>
                        <i class = "iconfont icon-butongyi" style="font-size:14px;margin-right:5px"></i> 取消
                    </Button>
                </div>
            </Modal>
            <Modal
                v-model = "modalStatus3"
                width='1000'
                :closable='false'
                :mask-closable="false"
                footer-hide>   
                <h3 style='text-align:center;font-weight:700;margin: 0 10px'>选择HIS收费项目</h3>  
                <div style="display: inline-block;margin: 10px 0 10px 0px;">
                    <Select class="w-select" clearable v-model="sflb" style="width:120px;" placeholder="项目分类">
                        <Option
                            v-for="item in ProjectSflbList"
                            :value="item.sflb"
                            :key="item.sflb"
                            style='text-align:center'
                        >{{item.sflb}}</Option>
                    </Select>
                </div>
                <div style="display: inline-block;margin: 10px 0 10px 10px;">
                    <Input
                    v-model.trim="xmmc"
                    placeholder="请输入项目名称检索"
                    style="width: 150px"
                    clearable
                    />
                </div>
                <div style="display: inline-block;margin: 10px 0 10px 10px;">
                    <Button type="primary" icon="ios-search" @click="getHisPage(1)"></Button>
                </div>
                <div style="display: inline-block;margin: 10px 0 10px 10px;float:right">
                    <Button type='primary' @click="getSynchronization" :disabled='showSpin'>
                        <Icon type="ios-checkmark" style="margin-right: 5px" />同步HIS收费项目
                    </Button>           
                </div>
                <Spin v-if="showSpin" fix></Spin>
                <Table @on-selection-change="selectChange" :loading="tableLoading" border stripe :columns="columns3" :data="data3" highlight-row ref="table" @on-current-change="handleRowChange"></Table>
                <Page
                :total="count"
                :current="pageNo"
                :pageSize="pageSize"
                style="margin-top:10px;text-align:center;"
                @on-change='pageChange'
            />
                <div style="text-align:center;margin:10px">
                    <Button @click="back" >
                        <i class = "iconfont icon-butongyi" style="font-size:14px;margin-right:5px"></i> 返回
                    </Button>
                </div>
            </Modal>
        </div>
    </div>
</template>
<script>
import api from "@/api/commonApi";
export default {
    data(){
        return{
            hospitalId: sessionStorage.getItem("hospitalId"),
            isBack: 2,
            id: '',
            isDisable: false, //按钮重复点击
            isubscribeDisable: false,//禁止预约项点击
            ipatientAppointmentDisable: false,//禁止患者预约项点击
            moldType: '',
            projectlist:[
                {dictName: '全部', dictValue: 0},            
                {dictName: '健康咨询', dictValue: 1},            
                {dictName: '巡诊', dictValue: 2},            
                {dictName: '检查项目', dictValue: 3},            
                {dictName: '检验项目', dictValue: 4},            
                {dictName: '治疗项目', dictValue: 5},  
                {dictName: '其他', dictValue: 6},  
            ],
            projectStatus: null,
            // 项目类型列表
            projectCategoryList: [
                {
                    name:"健康咨询",
                    id:'1'
                },
                {
                    name:"巡诊",
                    id:'2'
                },
                {
                    name:"检查项目",
                    id:'3'
                },
                {
                    name:"检验项目",
                    id:'4'
                },
                {
                    name:"治疗项目",
                    id:'5'
                },
                {
                    name:"手术项目",
                    id:'6'
                },
                {
                    name:"体检项目",
                    id:'7'
                },
                {
                    name:"其他",
                    id:'8'
                },
            ],
            Name: "",
            // 分页数据
            count: 0,
            pageNo: 1,
            pageSize: 10,
            // 弹出窗状态
            modalStatus1: false,
            modalStatus2: false,
            modalStatus3: false,       
            columns1: [
                {
                    key: "sum",
                    title: "排序",
                    align: "center",
                    width:80
                },
                {
                    key: "xmbm",
                    title: "HIS项目编码",
                    align: "center",
         
                },
                {
                    key: "xmmc",
                    title: "HIS项目名称",
                    align: "center",
                  
                },
                {
                    key: "jldw",
                    title: "计量单位",
                    align: "center",
                 
                },
                {
                    key: "dj",
                    title: "单价（元）",
                    align: "center",
                
                },
                {
                    key: "num",
                    title: "关联数量",
                    align: "center",
                    render:(h,params) => {
                        this.data1[params.index] = params.row
                        return [
                            h('div',
                                this.$refs.table1.$scopedSlots.num({
                                    row: params.row,
                                    idx: params.row._index
                                   
                                }),
                                1,
                             )
                        ]
                    }
                },
                {
                    key: "del",
                    title: "设置",
                    align: "center",
                    render:(h,params) => {
                        let row = params.row;
                        return [
                            h('Button', {
                                props: {
                                    type: "error",
                                    size: "small"
                                },
                                style: {
                                    margin: "0px 6px"
                                },
                                on: {
                                    click: () => {
                                        this.handleRemove(row);
                                    }
                                }
                            }, "删除")
                        ]
                    }
                },
            ],
            data1:[],
            sclxList:[],
            tab: '1',
            bc:'',
            bj: '1',
            type: '',
            editIndex: -1,
            inspection: '',
            typeName: '',
            sort: '',
            relatingCodes: '',
            columns2: [
                {
                    title: '编码排序',
                    key: 'sum',
                    align: "center",
                    width: 90,
                },
                {
                    key: "inspection",
                    title: "上级分类",
                    align: "center",
                    render: (h, params) => {
                        this.data2[params.index] = params.row
                        let inspection = params.row.inspection;
                        switch (inspection) {
                            case 1:
                                return "健康咨询";
                            case 2:
                                return "巡诊诊";
                            case 3:
                                return "检查项目";
                            case 4:
                                return "检验项目";
                            case 5:
                                return "治疗项目";
                            case 6:
                                return "手术项目";
                            case 7:
                                return "体检项目";
                            case 8:
                                return "其他";
                        }        
                        if(this.tab == '1' && this.type == '1' ){
                            return h(
                                'div',
                                this.$refs.myTable.$scopedSlots.inspection({
                                    row: params.row,
                                    idx: params.row._index
                                })
                            )
                        }
                        
                    }

                },
                {
                    title: '分类名称',
                    key: 'typeName',
                    align: "center",
                    render: (h, params) => {
                        this.data2[params.index] = params.row
                        let typeName = params.row.typeName;
                        if(this.tab != '1' ){
                            switch (typeName) {
                                case typeName:
                                return typeName;
                            }       
                        }
                         
                        if(this.tab == '1'){
                            return h(
                                'div',
                                this.$refs.myTable.$scopedSlots.typeName({
                                    row: params.row,
                                    idx: params.row._index
                                })
                            )
                        }
                        
                    }
                },
                {
                    title: '排序',
                    key: 'sort',
                    align: "center",
                    render: (h, params) => {
                        this.data2[params.index] = params.row
                        let sort = params.row.sort;
                        if(this.tab != '1'){
                            switch (sort) {
                                case sort:
                                return sort;
                            }       
                        }
                        if(this.tab == '1'){
                            return h(
                                'div',
                                this.$refs.myTable.$scopedSlots.sort({
                                    row: params.row,
                                    idx: params.row._index
                                })
                            )
                        }
                        
                    }
                },
                {
                    title: '关联码',
                    key: 'relatingCodes',
                    align: "center",
                    render: (h, params) => {
                        this.data2[params.index] = params.row
                        let relatingCodes = params.row.relatingCodes;
                        if(this.tab != '1'){
                            switch (relatingCodes) {
                                case relatingCodes:
                                return relatingCodes;
                            }       
                        }
                        if(this.tab == '1'){
                            return h(
                                'div',
                                this.$refs.myTable.$scopedSlots.relatingCodes({
                                    row: params.row,
                                    idx: params.row._index
                                })
                            )
                        }
                        
                    }
                },
                {
                    title: '设置',
                    key: 'idel',
                    align: "center",
                    render: (h, params) => {
                            return h(
                                'div',
                                this.$refs.myTable.$scopedSlots.idel({
                                    idx: params.row._index
                                })
                            )                      
                    }
                }
            ],
            data2:[],
            columns3:[
                {
                    key: "isum",
                    title: "排序",
                    align: "center",
                    width: 80,
                    render: (h, params) => {
                        let isum = (this.pageNo-1)*this.pageSize + params.index +1;
                        return h("span", isum);
                    }
                },
                {
                    key: "sflb",
                    title: "收费类别",
                    align: "center",
                   
                },
                {
                    key: "xmbm",
                    title: "项目编码",
                    align: "center",
                   
                },
                {
                    key: "xmmc",
                    title: "项目名称",
                    align: "center",
                   
                },
                {
                    key: "jldw",
                    title: "计量单位",
                    align: "center",
                   
                },
                {
                    key: "dj",
                    title: "单价",
                    align: "center",
                   
                },
                {
                    key: "zxks",
                    title: "执行科室",
                    align: "center",
                   
                },
                {
                    key: "sfdj",
                    title: "收费等级",
                    align: "center",
                   
                },
            ],
            data3:[],
            xmmc: '',
            // 表单验证以及项目详细数据
            formValidate: {
                // 项目类型
                projectCategory: "1",
                //项目分类
                itemType: '',
                //执行科室
                executiveDept: "",
                executiveDeptId: "",
                // 职称
                title: "",
                // 项目名称
                name: "",
                //检查部位,标本类型
                position: "",
                // 项目规格               
                norms: "",
                // 物价码
                priceCode: "",
                // 收费依据
                chargetrue: "",
                // 收费单位
                chargingUnit: "",
                // 收费依据
                priceBasis: "",
                // 备注
                reason: "",
                // 业务模块
                modular: "",
                // 启用标识
                status: true,
                itemUsed: true,
                // 标识Id
                id: "",
                // 医院ID
                hospitalId: sessionStorage.getItem("hospitalId"),
                // 咨询类型
                consult : "",
                // 咨询价格
                consultPrice: "",
                // 咨询问诊形式
                consultationForm: null,
                //是否为预约项
                isubscribe: false,
                //是否患者可以直接预约
                ipatientAppointment: "",
                //对应HIS项目
          
            },
            ruleValidate: {
                projectCategory: [{ required: true, message: '请选择项目', trigger: 'change' }],
                title: [{ required: true, message: '请选择关联职称', trigger: 'change' }],
                classify: [{ required: true, message: '请选择项目分类', trigger: 'change' }],
                position: [{ required: true, message: '请选择检查部位/标本类型', trigger: 'change' }],
                name: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
                chargingUnit: [{ required: true, message: '请选择收费单位', trigger: 'change' }],
                priceBasis: [{ required: true, message: '请输入收费单价', trigger: 'blur', type:'number' }],
                modular: [{ required: true, message: '请选择业务模块', trigger: 'change', type:'number'}],
                consult: [{ required: true, message: '请选择咨询类型', trigger: 'change'}],
                consultPrice: [{ required: true, message: '请输入咨询价格', trigger: 'blur', type:'number' }],
                consultationForm: [{ required: true, message: '请选择咨询问诊形式', trigger: 'change', type:'number' }],
                executiveDeptId: [{ required: true, message: '请选择执行科室', trigger: 'change' }],
            },
            
            //项目分类列表
            classificationList: [],
            //默认检查部位/标本类
            specimen:[],
            //执行科室列表
            departmentList: [],
            // 职称列表
            titleList: [],
            // 收费单位列表
            chargingUnit: [],
            //标本类列表
            specimenList: [],
            // 业务模块
            modular: [],
            Allmodular: ["健康咨询","问诊","复诊","续方","用药咨询"],
            // 咨询列表
            consultList: [
                { name: "健康咨询", id: 0 },
                { name: "用药咨询", id: 4 }
            ],
            // 问诊列表
            inquiryList: [
                { name: "问诊", id: 1 },
                { name: "复诊续方", id: 2 },
                // {
                //     name: "续方",
                //     id: 3
                // },
                
            ],
            //检查检验体检列表
            checklist: [
                { name: "通用", id: 1 },
                { name: "门诊预约", id: 2 },
                { name: "住院复查", id: 3 },
            ],
            consultationFormList: [
                {id: 0, name: '图文'},
                // {id: 1, name: '电话/语音'},
                {id: 2, name: '视频'}
            ],
            consultFormList: [
                {id: 0, name: '图文'},
            ],
            buttonName: "确认添加",
            // 咨询类型
            consultTypeList: [
                {
                    id:"1",
                    name:"图文咨询"
                },
                {
                    id:"2",
                    name:"视频咨询"
                },
                {
                    id:"3",
                    name:"语音咨询"
                }
            ],
            zj: 0,
            jgtype: '',
            whtitle: '项目分类维护',
            professTitle: '',
            ProjectSflbList: [
                {sflb: '检查项目'},
                {sflb: '检验项目'},
                {sflb: '治疗项目'},
                {sflb: '手术项目'},
                {sflb: '体检项目'},
                {sflb: '其他'},
            ],
            sflb: null,
            showSpin: false,
        }
    },
    created() {
        if(this.$store.state.resourceUrl == 'gphealth'){
            this.projectCategoryList = this.projectCategoryList.filter(col => col.name !== '巡诊');
            this.consultationFormList  = this.consultationFormList.filter(col => col.name !== '视频');
        }
        this.hospitalId =this.$route.query.hospitalId;
        this.jgtype =this.$route.query.jgtype;
        this.pageNo = this.$route.query.pageNo?parseInt(this.$route.query.pageNo):1;   
        if(this.formValidate.status == false ){
            this.formValidate.isubscribe = false
            this.isubscribeDisable = true   
        }
        if(this.formValidate.isubscribe == false){
            this.formValidate.ipatientAppointment = false
            this.ipatientAppointmentDisable = true   
        }  
    },
    mounted () {
        let pageNo = this.$route.query.pageNo;
        pageNo = pageNo ? pageNo : 1;
        // 职称列表
        this.getTitleList();
        //获取HIS收费项目
        this.getHisPage(pageNo)
    },
    methods:{
        //是否启用控制其他俩个按扭的状态
        changeStatus(val){
            if(val == false){
                this.formValidate.isubscribe =  false
                this.formValidate.ipatientAppointment = false
                this.isubscribeDisable = true
                this.ipatientAppointmentDisable = true              
            } else {
                this.isubscribeDisable = false           
            }
        },
        changeisubscribe(val){
            if(val == false){
                this.formValidate.ipatientAppointment = false
                this.ipatientAppointmentDisable = true               
            } else {
                this.ipatientAppointmentDisable = false
            }
        },
         //表格
        selectChange(selections) {
            this.selections = selections;
        },
        // 根据项目类型切换不同的业务模块
        projectCategoryChange () {
            this.formValidate.modular = ''
            this.getClassificationList();
            console.log(this.formValidate.projectCategory)  
            // 页面查询的科室选择框
            if(this.formValidate.projectCategory !='1' && this.formValidate.projectCategory !='2' && this.formValidate.projectCategory !=''){
                this.loadingDepartment()
            }                 
        },
        loadingDepartment(){
            let url = api.findDeptName
            let params = {
                hospitalId : this.formValidate.hospitalId,
                medicalTechnology: 1
            }
            this.packageAxios(this,url,params,(res)=>{
                if(res.data.success) {
                    let ret = res.data.object;                  
                    this.departmentList = ret;
                } else {
                    this.$Message.error("加载失败")
                }
            })
        },
        //计算总价
        money(){
            this.zj = 0
            if (this.data1 && this.data1.length) {               
                this.data1.map(item => {  
                    if(item.num){
                        this.zj += Number(item.dj)*Number(item.num);
                    }                
                    
                })
            } 
            this.zj = this.zj.toFixed(2);       
        },
        // 保存新增
        handleSubmit (name) {
            // this.isDisable = true  //不可点击
            this.$refs[name].validate((valid) => {
                if (valid) {
                    if(String(this.formValidate.priceBasis).indexOf('.')!=-1 && String(this.formValidate.priceBasis).split('.')[1].length>2){
                        this.$Message.error('项目平台收费标准请保留两位小数!');
                        this.isDisable = false  //放开点击了
                        return;
                    }
                    let url = api.insertsingleItem;
                    let params = {
                        "hospitalId": this.formValidate.hospitalId,
                        "itemCode": this.formValidate.priceCode,
                        "itemFeeBasis": this.formValidate.charge,
                        "itemFeePrice": this.formValidate.priceBasis,
                        "itemFeeUnit": this.formValidate.chargingUnit,
                        "itemName": this.formValidate.name,
                        "itemSpec": this.formValidate.norms,
                        "itemType": this.formValidate.projectCategory,
                        "itemUsed": Number(this.formValidate.status),
                        "remark": this.formValidate.reason,
                    }
                    this.chargingUnit.forEach(i => {
                        if(i.id == this.formValidate.chargingUnit){
                            params.itemFeeUnitName = i.name
                        }
                    })
                    if(this.formValidate.executiveDeptId){
                        this.departmentList.forEach(z => {
                            if(z.id == this.formValidate.executiveDeptId){
                                params.executiveDeptName = z.deptNickname
                                params.executiveDept = z.dictType
                            }
                        })    
                    }  
                    if(this.formValidate.classify){
                        this.classificationList.forEach(z => {
                            if(z.id == this.formValidate.classify){
                                params.classifyName = z.typeName
                            }
                        })    
                    }
                    if(this.formValidate.position){
                        this.specimen.forEach(z => {
                            if(z.id == this.formValidate.position){
                                params.positionName = z.typeName
                            }
                        })    
                    }                                
                    if(this.formValidate.projectCategory ==1 || this.formValidate.projectCategory == 2){
                        params.title = this.formValidate.title,
                        params.serviceType =this.formValidate.modular,
                        params.consultationForm =this.formValidate.consultationForm
                    } else {
                        params.classify =this.formValidate.classify,
                        params.executiveDeptId =this.formValidate.executiveDeptId,
                        params.position =this.formValidate.position,
                        params.ipatientAppointment = Number(this.formValidate.ipatientAppointment),
                        params.isubscribe =  Number(this.formValidate.isubscribe)    
                    } 
                    // else {
                    //     params.classify =this.formValidate.classify,
                    //     params.executiveDeptId =this.formValidate.executiveDeptId,
                    //     params.position =this.formValidate.position,
                    //     params.isubscribe = 0,
                    //     params.ipatientAppointment = 0
                    // }
                    let hisChargeList = 
                        this.data1.map(i=>({
                            hisTechnologyName : i.xmmc,
                            hisTechnologyCode : i.xmbm,
                            num: Number(i.num),
                            dj: i.dj,
                            jldw: i.jldw,
                            chargeId:i.chargeId
                        }))                  
                    params.hisChargeList =  hisChargeList 
                    if(this.jgtype == 'jianguan') {
                        url = api.insertSuperviseServiceItemCharge
                    }  
                    this.$axios.post(url, params).then(res => {
                        if(res.data.success) {
                            this.$Message.success('保存成功')
                            this.isDisable = false;//不可点击
                            // 弹窗数据初始化
                            this.handleReset('formValidate');
                            this.modalStatus = false;                                 
                        } else {
                            this.isDisable = false;//不可点击
                            this.$Message.error(res.data.message)
                        }
                    }).catch(err => {
                            this.isDisable = false;//放开点击了
                            console.log(err);
                        });
                } else {
                    this.$Message.error('请完整填写必填项!');
                    this.isDisable = false  //不可点击
                }
            })
        },
        // 取消保存
        handleReset (name) {
            // this.$refs[name].resetFields();
            this.formValidate.projectCategory = ''
            // 职称
            this.formValidate.title = ''
            // 项目名称
            this.formValidate.name = ''
            // 项目规格
            this.formValidate.norms = ''
            // 物价码
            this.formValidate.priceCode = ''
            // 收费依据
            this.formValidate.charge = ''
            // 收费单位
            this.formValidate.chargingUnit = ''
            // 收费依据
            this.formValidate.priceBasis = ''
            // 备注
            this.formValidate.reason = ''
            //项目分类
            this.formValidate.classify = ''
            //执行科室
            this.formValidate.executiveDept = ''
            this.formValidate.executiveDeptId = ''
            //默认检查部位/标本类
            this.formValidate.position = ''
            // 业务模块
            this.formValidate.modular = ''
            //咨询/问诊形式
            this.formValidate.consultationForm = ''
            // 启用标识
            this.formValidate.status = false
            this.formValidate.ipatientAppointment = false
            this.formValidate.isubscribe = false
            // 标识Id
            this.formValidate.id = ''
            this.modalStatus = false
            this.formValidate.consult = ''
             this.formValidate.consultPrice = ''
             let query = this.$route.query
            if(this.jgtype == 'jianguan') {
                this.functionJS.queryNavgationTo(
                    this,
                    "/index/supervision/secordTrial/list",{
                        hospitalId:this.hospitalId,
                        chargeInfoModal:true,
                    }
                );
            } else{
                this.functionJS.queryNavgationTo(
                    this,
                    "/index/directory/priceManagement/index",{
                        hospitalId:this.hospitalId,
                    }
                );
            } 
            this.tab = '2'
        },
        //获取项目分类列表
        getClassificationList (val) {   
            if(val == 0){
                this.whtitle = "项目分类维护"
            } else {
                this.whtitle = "默认部位/标本类型维护"
            } 
            let params = {
                "hospitalId": this.formValidate.hospitalId,
                "inspection": this.formValidate.projectCategory,
                "moldType": val,
                "idel": 0,
            }
            this.$axios
                .post(api.findMedicalTechnology, params)
                .then(resp => {
                    console.log(params) 
                    let ret
                    if(resp.data.success){
                        if(resp.data.object){
                            ret = resp.data.object
                            ret.forEach((item,index) => {
                                // 排序
                                item.sum = this.addZeros(index)
                            })  
                            if(val == 0){
                                this.classificationList = ret;  
                                this.data2 = this.classificationList     
                            } else {
                                this.specimen = ret
                                this.data2 = this.specimen
                            }                     
                        } else{
                            if(val == 0){
                                this.classificationList = [];  
                                this.data2 = []    
                            } else {
                                this.specimen = []
                                this.data2 = []
                            }        
                        }
                   
                        console.log('字典列表',this.classificationList)    
                    }
                                    
                })
                .catch(err => {
                    console.log(err);
                });
        },
        changeModular(val) {
            if(val==4) {
                this.professTitle = 2
            } else {
                this.professTitle = 1
            }          
            this.getTitleList ()
        },
        //获取职称列表
        getTitleList () {
            // this.$axios
            //     .post(api.getTitle, {})
            //     .then(resp => {
            //         this.titleList = resp.data.object;
            //     })
            //     .catch(err => {
            //         console.log(err);
            //     });
            // getTitle   获取全部职称接口
            this.$axios
                .post(api.findDoctorTitleListByDoctorType,{type: this.professTitle})
                .then(resp => {
                    this.titleList = resp.data.object;
                })
                .catch(err => {
                    console.error(err);
                });
                // 加载收费列表
            this.$axios.post(api.findFeeEnum,{}).then(resp => {
                if(resp.data.success) {
                    let ret = resp.data;
                    this.chargingUnit = ret.object;
                }
            })
        },
        //获取院内his收费项目类别列表
        getProjectSflbList(){
            let params = {
                "hospitalId": this.formValidate.hospitalId,             
            }
            this.$axios
                .post(api.findHisProjectSflbList, params)
                .then(resp => {                  
                    let ret = resp.data.object;
                    if(ret[0] !=null ) {
                        this.ProjectSflbList = ret   
                    } else {
                        // this.ProjectSflbList = [
                        //     {sflb: '检查项目'},
                        //     {sflb: '检验项目'},
                        //     {sflb: '治疗项目'},
                        //     {sflb: '手术项目'},
                        //     {sflb: '体检项目'},
                        //     {sflb: '其他'},
                        // ]
                        this.ProjectSflbList = []
                    }       
                })
                .catch(err => {
                    console.log(err);
                });
        },
        //获取HIS收费项目
        getHisPage(pageNo){
            this.pageNo  = pageNo
            let params = {
                "hospitalId": this.formValidate.hospitalId,
                "pageNo": pageNo,
                "pageSize": this.pageSize,   
                "sflb": this.sflb ? this.sflb : null,                  
            }
            if (this.xmmc != "") {
                params.xmmc = this.xmmc.trim();
            }
            this.$axios
                .post(api.findHisProjectPage, params)
                .then(resp => {                  
                    this.count = resp.data.object.total;
                    let ret = resp.data.object;
                    if(ret.records){
                        this.data3 = ret.records
                        ret.records.forEach((item,index) => {
                            // 排序
                            item.sum = this.addZeros(index)
                        })                          
                    } else {
                        this.data3 = []
                    }  
                    // console.log("回参 ",ret)                  
                })
                .catch(err => {
                    console.log(err);
                });
        },
        //选择his收费项目
        handleRowChange(currentRow, oldCurrentRow){
            console.log(currentRow)   
            currentRow.num= 1        
            this.data1.push(currentRow) 
            console.log(this.data1)
            this.data1.forEach((item,index) => {
                // 排序
                item.sum = this.addZeros(index)
                if(item.num){
                    this.money()
                }
            })
        },
        //同步机构his项目信息
        getSynchronization(){
            this.showSpin = true
            let params = {
                "hospitalId": this.hospitalId,
                "pageNo": this.pageNo,
                "pageSize": this.pageSize,   
                "inspection": this.formValidate.projectCategory,                
                "moldType": 0   
            }
            if (this.xmmc != "") {
                params.xmmc = this.xmmc.trim();
            }
            this.$axios
                .post(api.synHisProject, params)
                .then(resp => {
                    if(resp.data.code == 1) {
                        let ret = resp.data.object;
                        this.showSpin = false
                        this.$Message.success('同步成功')
                        this.getHisPage(1)
                    } else {
                        this.showSpin = false
                        this.$Message.error(resp.data.message)
                    } 
                })
                .catch(err => {
                    this.showSpin = false
                    console.log(err);
                });
        },
        //删除选择的HIS收费项目
        handleRemove(val){
            this.data1.forEach((i,index) =>{
                if(index == val._index){
                    this.data1.splice(val._index, 1)
                }
            })      
            //计算总价
            this.money()
        },
        //添加项目分类
        addClassification(){
            // console.log(this.formValidate.projectCategory)
            this.modalStatus1 = true
            this.moldType = 0
            this.editIndex='-1'
            this.bj = '1'
            this.bc = ''
            this.getClassificationList (0)
        },
        //添加默认检查部位/标本字典
        addposition(){
            this.modalStatus1 = true
            this.moldType = 1
            this.editIndex='-1'
            this.bj = '1'
            this.bc = ''
            this.getClassificationList (1)
        },
        //编辑项目分类列表
        handleEdit (row, index) {
            this.editIndex = index;
            this.type = ''    
        },
        //修改字典后保存
        editsub(val,index){
            let params = {
                "hospitalId": this.hospitalId
            }
            val.map(i=>{
                if(i._index == index){
                    params.typeName= i.typeName
                    params.inspection = i.inspection
                    params.sort = i.sort
                    params.relatingCodes = i.relatingCodes
                    params.id = i.id
                    params.moldType = this.moldType
                }
            })
            if (params.inspection == "") {
                this.$Message.info("上级分类不能为空");
            } else if (params.typeName == "") {
                this.$Message.info("分类名称不能为空");
            } else if (params.sort == "") {
                this.$Message.info("排序不能为空");
            } else if (params.relatingCodes == "") {
                this.$Message.info("关联码不能为空");
            } else{
                this.$axios
                .post(api.updatetMedical, params)
                .then(resp => {
                     console.log(params)
                    let ret = resp.data.object;
                    this.getClassificationList(this.moldType)
                    console.log(ret)
                })
                .catch(err => {
                    console.log(err);
                });               
                this.editIndex = '-1';
            
            }          
        },
        //保存新增字典
        sub(val,index){
            let params = {
                "hospitalId": this.formValidate.hospitalId
            }
            val.map(i=>{
                if(i._index == index){
                    let inspection
                    if(i.inspection == "检查项目"){
                        inspection = 3
                    } else if(i.inspection == "检验项目"){
                        inspection = 4
                    } else if(i.inspection == "治疗项目"){
                        inspection = 5
                    } else if(i.inspection == "手术项目"){
                        inspection = 6
                    } else if(i.inspection == "体检项目"){
                        inspection = 7
                    } else {
                        inspection = 8
                    }            
                    params.inspection = inspection
                    params.moldType = this.moldType
                    params.relatingCodes = i.relatingCodes
                    params.sort = i.sort
                    params.typeName= i.typeName
                }
            })
            if (params.inspection == "") {
                this.$Message.info("上级分类不能为空");
            } else if (params.typeName == "") {
                this.$Message.info("分类名称不能为空");
            } else if (params.sort == "") {
                this.$Message.info("排序不能为空");
            } else if (params.relatingCodes == "") {
                this.$Message.info("关联码不能为空");
            } else{
                console.log(params)
                this.$axios
                .post(api.insertMedical, params)
                .then(resp => {
                    if(resp.data.success) {
                        let ret = resp.data.object;
                        console.log(ret)
                        this.$Message.success('保存成功')
                        this.bc = ''
                        this.bj ='1'
                        this.editIndex='-1'
                        this.getClassificationList(this.moldType)
                    } else {
                            this.isDisable = true;//放开点击了
                            this.$Message.error(resp.data.message)
                        }
                })
                .catch(err => {
                    console.log(err);
                });   
                this.bc = ''
                this.bj ='1'
                this.editIndex = '-1';     
            }          
        },
         //添加HIS项目
        his(){
            this.modalStatus3 = true
            this.sflb = null
            // this.getProjectSflbList()
            this.getHisPage(this.pageNo)
        },
        //新增项目字典
        add(val){
            let inspection
            if(this.formValidate.projectCategory == 3){
                 inspection = "检查项目"
            } else if(this.formValidate.projectCategory == 4){
                 inspection = "检验项目"
            } else if(this.formValidate.projectCategory == 5){
                 inspection = "治疗项目"
            } else if(this.formValidate.projectCategory == 6){
                 inspection = "手术项目"
            } else if(this.formValidate.projectCategory == 7){
                 inspection = "体检项目"
            } else {
                 inspection = "其他"
            }    
            this.bc = '1'
            this.tab = '1'
            this.type = '1'
            this.bj = ''
            this.editIndex = '-1'
            this.data2.push({
                typeName: '',
                sort: '',
                relatingCodes: '',
                inspection: inspection
            })        
        },
        /** 删除行 */
        delRow(val,index) {
            // this.data2.splice(idx, 1)
            let params = {
                "hospitalId": this.hospitalId
            }
            val.map(i=>{
                if(i._index == index){
                    params.id= i.id
                    params.idel = 1
                    params.moldType = 0
                }
            })
            this.$axios
                .post(api.updateDictPage, params)
                .then(resp => {
                     console.log(params)
                    let ret = resp.data.object;
                    console.log(ret)
                })
                .catch(err => {
                    console.log(err);
                });
            this.getClassificationList()
        },
        //弹窗返回
        back(){
            this.modalStatus1 = false
            
            this.modalStatus3 = false
            this.sflb = null
            this.xmmc = null
            
        },
        // 分页器改变
        pageChange(index) {
            this.pageNo = index;
            if (this.Name) {
                this.getHisPage(index, this.Name);
            } else {
                this.getHisPage(index);
            }
            this.getClassificationList(index)
        },
    },
    watch: {
        'pageSize'(nv, ov) {
            this.getHisPage(this.pageNo)
        },
    }
}
</script>
<style lang="less" scoped>
.edit{
    padding: 10px 30px;
    width: 100%;
    background: #ffffff;
    box-sizing: border-box;
    .main{
        margin-top:10px;       
        .infobox {
            margin: 10px auto;
            border: 1px solid #f0f0f0;
            box-shadow: 0 4px 3px #ebedf8;
            border-radius: 5px;
            margin-bottom: 20px;
            .box{
                padding: 0 20px;
            }
            .title {
                font-size: 20px;
                padding-left: 15px;
                margin-bottom: 20px;
                color: #333;
                height: 40px;
                line-height: 40px;
                background: #ebedf8;         
            }
            .hongdian {
                margin-left: 10px;
            }
        }
    }   
    Button{
        border-radius: 20px;
    }
}
</style>